package cn.com.dhcc.tlq;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;

import cn.com.dhcc.app.core.util.XstreamUtil;
import cn.com.dhcc.turbo.entity.exch.FileData;

public class TurboFilePackUtil extends FilePacketUtil{
	private static String XML_SUFFIX=".xml";
    /**
     * 打包
     * @param sources 要打包的文件
     * @param fileData 要打包的对象，这个对象会通过xml字符串成打包文件
     * @param target
     * @return
     */
	public static String tar(List<?> sources,FileData fileData,String target){
		 TarArchiveOutputStream out = null;  
    	//构造输出流
    	 try {
    	     out = new TarArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(target)),DEFAULT_ENCODING); //输出流
    		 tarProcess(sources, out);
    		 tarString(XstreamUtil.toXml(fileData), fileData.getOrderId()+XML_SUFFIX, out, "");
		} catch (Exception e1) {
			e1.printStackTrace();
		}finally{//资源关闭
			if (out!=null) {
				IOUtils.closeQuietly(out);
			}
		}
		return target;
	}
}
